package com.atguigu.blog.service.impl;

import com.atguigu.blog.entity.Article;
import com.atguigu.blog.entity.Category;
import com.atguigu.blog.mapper.ArticleMapper;
import com.atguigu.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    //列表
    @Override
    public List<Article> getList() {
        return articleMapper.getList();
    }
    /**
     * 1.1 文章列表展现
     * @author Petrichor
     * @date 2023/10/23 15:22
     **/
    @Override
    public List<Article> getArticle(Long cid) {
        return articleMapper.getArticle(cid);
    }
    /**
     * 1.3 根据文章ID查询详情信息
     * @author Petrichor
     * @date 2023/10/23 17:36
     **/
    @Override
    public Article findArticleById(Long id) {
        return articleMapper.findArticleById(id);
    }
    /**
     * 3.2 文章新增实现
     * @author Petrichor
     * @date 2023/10/24 14:47
     **/
    @Override
    public void saveArticle(Article article) {
        article.setCreateTime(new Date());
        article.setUpdateTime(article.getCreateTime());
        articleMapper.saveArticle(article);
    }
    /**
     * 3.3 文章删除
     * @author Petrichor
     * @date 2023/10/24 16:18
     **/
    @Override
    public void deleteArticleById(Long id) {
        articleMapper.deleteArticleById(id);
    }
    /**
     * 文章修改
     * @author Petrichor
     * @date 2023/10/24 16:18
     **/
    @Override
    public void updateArticle(Article article) {
        article.setUpdateTime(new Date());
        articleMapper.updateArticle(article);
    }

}
